package com.jarvan.utils;

import com.alibaba.fastjson.JSON;
import com.jarvan.dto.TrainDto;
import com.jarvan.model.Trains;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class TrainsSerialize {
    public static List<TrainDto> convert(List<Trains> list){
        List<TrainDto> dtoList = new ArrayList<>();
        list.forEach(e -> {
            TrainDto dto = new TrainDto();
            BeanUtils.copyProperties(e, dto);
            dto.setStationInfos(JSON.parseArray(e.getStations(), String.class));
            dtoList.add(dto);
        });
        return dtoList;
    }
}
